package com.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
	private String username;
	private File  upload;
	private String uploadContentType;
	private String uploadFileName;
	
	
	public String execute() throws Exception{
		//1.获取上传的文件绝对路径
		String path = ServletActionContext.getServletContext().getRealPath("/upload");
		//2.创建输出流，位置是服务器
		FileOutputStream fos = new FileOutputStream(path+"\\"+uploadFileName);
		//3.创建输入流对象，上传的文件---在临时路径
		FileInputStream fis = new FileInputStream(upload);
		//4.边读边写
		byte[] b = new byte[1024];
		int len =0;
		while(   (len=fis.read(b)) != -1 ){
			fos.write(b,0,len);
		}
		fos.close();
		fis.close();
		return "success";
	}


	public String getUsername() {
		return username;
	}


	public void setUsername(String username) {
		this.username = username;
	}


	public File getUpload() {
		return upload;
	}


	public void setUpload(File upload) {
		this.upload = upload;
	}


	public String getUploadContentType() {
		return uploadContentType;
	}


	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}


	public String getUploadFileName() {
		return uploadFileName;
	}


	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	
}
